<?php
class mapa_chunk{
	var $params;
	function mapa_chunk ($params=array()){
		$this->params=$params;
	}
	function out($params=array()){
		global $config, $document,$result;
		$plantilla= file_get_contents($config->paths["chunks/html"].'mapa.html');
		if($document){
			$document->addScript("http://maps.googleapis.com/maps/api/js?sensor=true&libraries=places&amp;language=es");
			$document->addScript("js/mapa.js");
			$document->addScript("js/mapa.js");
			$document->addStyle("css/mapa.css");
			$document->addScript("js/dondeestoy.js");
			if($this->params["orientacion"]=="true"){
				$document->addScript("js/orientacion.js");
				}
		}
		$this->params["key"]=md5("aaaa".rand());
		
		switch($this->params["center"]){
			case "firstResult":
				if($result[0]){
					$this->params["center"]="new google.maps.LatLng(".$result[0]->get("lat").", ".$result[0]->get("lon").")";}
				else{
					$this->params["center"]="new google.maps.LatLng(-34.397, 150.644)";
				}
				break;
			default:
				$this->params["center"]=$this->params["center"]?$this->params["center"]:"new google.maps.LatLng(-34.397, 150.644)";
		}
		
		
		$this->params["mapTypeId"]=$this->params["mapTypeId"]?$this->params["mapTypeId"]:"google.maps.MapTypeId.ROADMAP";
		$this->params["zoom"]=$this->params["zoom"]?$this->params["zoom"]:8;
		$this->params["tilt"]=45;
		
		
		
		$p=array(
			"#KEY#"=>$this->params["key"],
			"#WIDTH#"=>$this->params["width"],
			"#HEIGHT#"=>$this->params["height"],
			"#PARAMS#"=>json_encode($this->params)
			);
		
		return str_replace(array_keys($p), $p, $plantilla);
	}
}
